import requests


class Request():

    def __init__(self, method, urls, data):

        self.urls = urls
        self.data = data
        self.method = method

    def request_get(self):
        result = requests.get(url=self.urls, data=self.data)
        return result.text

    def request_post(self):
        result = requests.post(url=self.urls, data=self.data)
        return result.text

    def request_all(self):
        """
        根据传的method来进行不同的请求，并拿到请求后的响应结果
        :return:
        """
        res = ''
        if self.method and self.urls is not None:
            if self.method == 'post':
                res = self.request_post()
            elif self.method == 'get':
                res = self.request_get()
            else:
                print('Excel中的请求method值错误！')
        else:
            return 'method 或 urls 不可未空'
        return res


if __name__ == '__main__':
    url = 'http://www.baidu.com'
    re = Request(method='get', urls=url, data=None)
    print(re.request_all())

